﻿using System;
using System.Windows.Forms;
using System.Linq;
using PhoneReference.DataLayer;



namespace PhoneReference
{
    public partial class Form1 : Form
    {
        public DataHandlingLocation dhl = new DataHandlingLocation();
        public Form1()
        {
            InitializeComponent();
        }
        
        private void Form1_Load(object sender, EventArgs e)
        {
            ShowGridLocation();
                        
           
        }

        private void ShowGridLocation()
        {
            dataGridView1.DataSource = dhl.ShowAllRecords();
            dataGridView1.Columns[0].Visible = false;
            dataGridView1.Columns[1].HeaderText = "Номер";
            dataGridView1.Columns[2].HeaderText = "Наименование";
            dataGridView1.Columns[3].Visible = false;
            dataGridView1.Columns[4].Visible = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
          
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                dhl.AddRecords(txtLocation.Text, txtNubber.Text);
                ShowGridLocation();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
             
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            
            try
            {
                dhl.DeleteRecords((int)dataGridView1.CurrentRow.Cells[0].Value);
                ShowGridLocation();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        
    }
}
